#ifndef __SH1106_H
#define __SH1106_H

#include "ti_msp_dl_config.h"
#include <stdint.h>
#include <stdbool.h>
#include <string.h>

// SH1106 OLED 显示屏参数
#define SH1106_WIDTH    128
#define SH1106_HEIGHT   64
#define SH1106_PAGES    8   // 64/8 = 8页

// SH1106 命令定义
#define SH1106_CMD_DISPLAY_OFF              0xAE
#define SH1106_CMD_DISPLAY_ON               0xAF
#define SH1106_CMD_SET_DISPLAY_CLOCK_DIV    0xD5
#define SH1106_CMD_SET_MULTIPLEX            0xA8
#define SH1106_CMD_SET_DISPLAY_OFFSET       0xD3
#define SH1106_CMD_SET_START_LINE           0x40
#define SH1106_CMD_CHARGE_PUMP              0x8D
#define SH1106_CMD_MEMORY_ADDR_MODE         0x20
#define SH1106_CMD_SEG_REMAP                0xA0
#define SH1106_CMD_COMDIR                   0xC0
#define SH1106_CMD_SET_COM_PINS             0xDA
#define SH1106_CMD_SET_CONTRAST             0x81
#define SH1106_CMD_SET_PRECHARGE            0xD9
#define SH1106_CMD_SET_VCOM_DETECT          0xDB
#define SH1106_CMD_DISPLAY_ALL_ON_RESUME    0xA4
#define SH1106_CMD_NORMAL_DISPLAY           0xA6
#define SH1106_CMD_COLUMN_ADDR              0x21
#define SH1106_CMD_PAGE_ADDR                0x22
#define SH1106_CMD_SET_PAGE_START           0xB0
#define SH1106_CMD_SET_COLUMN_LOW           0x00
#define SH1106_CMD_SET_COLUMN_HIGH          0x10

// 颜色定义
#define SH1106_BLACK    0
#define SH1106_WHITE    1

// 字体大小
typedef enum {
    FONT_SIZE_6x8 = 0,
    FONT_SIZE_8x16
} sh1106_font_size_t;

// 函数声明
void SH1106_Init(void);
void SH1106_Reset(void);
void SH1106_WriteCommand(uint8_t cmd);
void SH1106_WriteData(uint8_t data);
void SH1106_SetCursor(uint8_t x, uint8_t page);
void SH1106_Clear(void);
void SH1106_ClearImmediate(void);
void SH1106_Display(void);
void SH1106_SetPixel(uint8_t x, uint8_t y, uint8_t color);
void SH1106_DrawChar(uint8_t x, uint8_t page, char ch, sh1106_font_size_t font_size);
void SH1106_DrawString(uint8_t x, uint8_t page, const char *str, sh1106_font_size_t font_size);
void SH1106_DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color);
void SH1106_DrawRectangle(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color);
void SH1106_FillRectangle(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color);
void SH1106_SetContrast(uint8_t contrast);
void SH1106_DisplayOn(void);
void SH1106_DisplayOff(void);
void SH1106_InvertDisplay(bool invert);

// 延时函数
void SH1106_Delay_ms(uint32_t ms);

#endif /* __SH1106_H */ 